import App from './App'
import Vue from 'vue'
import store from './store'
import {router,RouterMount} from './router/index.js'  //路径换成自己的

import {
	http
} from '@/api/service.js' // 全局挂载引入，配置相关在该index.js文件里修改
import uView from "uview-ui";

import {
	setTicket
} from './utils/auth'
import {
	login
} from './api/user.js'
import {
	isEmpty,
	getQueryVariable
} from './utils/utils.js'

Vue.use(uView)
Vue.use(router)
Vue.prototype.$store = store
Vue.prototype.$http = http
Vue.config.productionTip = false
Vue.config.ignoredElements.push('wx-open-launch-weapp')

let appType = uni.getStorageSync('appType');
// #ifdef H5
	if(process.env.NODE_ENV !== 'development'){
		appType = 'mp-p'
	}
// #endif
console.log(`appType:${appType}`)
if (!isEmpty(appType)) {
	store.commit('app/switchAppType', appType);
}

let tchJson = uni.getStorageSync('tchInfo');
if (!isEmpty(tchJson)) {
	let user = JSON.parse(tchJson);
	store.commit('user/setTeacherInfo', user);
}

let parentJson = uni.getStorageSync('parentInfo');
if (!isEmpty(parentJson)) {
	let user = JSON.parse(parentJson);
	store.commit('user/setParentInfo', user);
}

//http://localhost:8080/wx/api/materials/newMomsFood?testUser=1
// #ifdef H5
	if(process.env.NODE_ENV !== 'development'){
		let href = window.location.href;
		login(href).then(res => {
			console.log(res);
			store.commit('user/setParentInfo', res.data);
			setTicket(res.data.ticket);
		}).catch(res => {
			console.log(res);
			if (res.code === "2000002") {
				window.location.replace(res.data)
			}
		})
	}
// #endif

App.mpType = 'app'
const app = new Vue({
	...App,
	store
})

//v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
// #ifdef H5
	RouterMount(app,router,'#app')
// #endif

// #ifndef H5
	app.$mount(); //为了兼容小程序及app端必须这样写才有效果
// #endif

export default app
